//
//  AddViewController.m
//  map
//
//  Created by dllo on 16/4/25.
//  Copyright © 2016年 王彦森. All rights reserved.
//

#import "AddViewController.h"
#import "EaseMob.h"
#import "FriendViewController.h"

@interface AddViewController ()<EMChatManagerDelegate>
@property(nonatomic,strong)UITextField *userName;
@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.userName = [[UITextField alloc]initWithFrame:CGRectMake(120, 85, 120, 40)];
    self.userName.layer.borderWidth = 1.5;
    self.userName.layer.cornerRadius = 15;
    [self.view addSubview:self.userName];
    
    UIButton * add = [UIButton buttonWithType:UIButtonTypeSystem];
    [add addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
    [add setTitle:@"添加" forState:UIControlStateNormal];
    add.frame = CGRectMake(120, 125, 50, 40);
    [self.view addSubview:add];
  
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    UIButton *group = [UIButton buttonWithType:UIButtonTypeSystem];
    group.frame = CGRectMake(20, 10, 100, 50);
    group.backgroundColor = [UIColor cyanColor];
    [group setTitle:@"添加群组" forState:UIControlStateNormal];
    [group addTarget:self action:@selector(createGroup:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:group];
    
}

//创建数组的点击方法
-(void)createGroup:(UIButton*)add{
        EMGroupStyleSetting *groupStyleSetting=[[EMGroupStyleSetting alloc]init];
        groupStyleSetting.groupMaxUsersCount = 30;//设置群员的个数,默认为200
        groupStyleSetting.groupStyle = eGroupStyle_PublicOpenJoin;//创建不同类型的群组
    
    
        //参数1:群组的名字
        //参数2:群组的描述
        //参数3:群组的成员
        //
    //    NSArray *Arr = self.groupArr;
       [[EaseMob sharedInstance].chatManager asyncCreateGroupWithSubject:@"好难" description:@"真的好难" invitees: @[@"00"] initialWelcomeMessage:@"不知道奥" styleSetting:groupStyleSetting completion:^(EMGroup *group, EMError *error) {
           if (!error) {
               NSLog(@"群组创建成功:%@",group);
           }else{
               NSLog(@"创建群组失败的原因:%@",error);
           }
           
           
       } onQueue:dispatch_get_main_queue()];


}





-(void)add:(UIButton*)button{
    NSString *message = [@"" stringByAppendingString:[[EaseMob sharedInstance].chatManager loginInfo][@"username"]];
    EMError *error = nil;
    
    [[EaseMob sharedInstance].chatManager addBuddy:self.userName.text message:message error:&error];
    if (error) {
        NSLog(@"添加好友有问题:%@",error);
//        FriendViewController *fir = [[FriendViewController alloc]init];
    }else{
        NSLog(@"添加好友没有问题");
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    }
}




-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.userName resignFirstResponder];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
